
package com.wisdytech.linkdcs.equipment.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.github.pagehelper.PageInfo;
import com.wisdytech.common.bean.BasePageInfo;
import com.wisdytech.common.bean.Filter;
import com.wisdytech.common.constants.CommonConstants;
import com.wisdytech.common.handler.BaseService;
import com.wisdytech.common.utils.DataTransformUtil;
import com.wisdytech.linkdcs.equipment.dao.IEqEquipmentDao;
import com.wisdytech.linkdcs.equipment.dao.IEqStatusDao;
import com.wisdytech.linkdcs.equipment.model.Equipment;
import com.wisdytech.linkdcs.equipment.model.Status;
import com.wisdytech.linkdcs.equipment.service.IEquipmentStatusService;
import com.wisdytech.linkdcs.equipment.vo.EquipmentStatusVO;

@Service("equipmentStatusService")
@Transactional
public class EquipmentStatusServiceImpl extends BaseService<IEqStatusDao, Status>  implements IEquipmentStatusService {
    
    @Override
    public PageInfo<Status> listEquipmentStatusByFilter(String opId,String eqCode, String eqName, Filter filter) {
        
        Map<String,String> params =new HashMap<String,String>();
        if(StringUtils.isNotBlank(opId)){
            params.put("opId", opId);
        }
        if(StringUtils.isNotBlank(eqCode)){
            params.put("eqCode", eqCode);
        }
        if(StringUtils.isNotBlank(eqName)){
            params.put("eqName", eqName);
        }
        
        List<Status> statusList=
                super.beforeList(IEqStatusDao.class, filter).selectEqStatus(params);
        PageInfo<Status> pageInfo =new PageInfo<>(statusList);
        
        return pageInfo;
    }

    @Override
    public BasePageInfo listEquipRealStatus(String opId,String eqId, String eqName, Filter filter) {
        //获取设备
        
        
        EntityWrapper<Equipment> ew =new EntityWrapper<>();
        if(StringUtils.isNotBlank(opId)){
            ew.eq("OPERATION_ID", opId);
        }
        
        if(StringUtils.isNotBlank(eqId)){
            ew.eq("EQUIP_CODE", eqId);
        }
        if(StringUtils.isNotBlank(eqName)){
            ew.like("EQUIP_NAME", eqName);
        }
        ew.eq("del_flag", CommonConstants.DEL_FLAG);
        filter.setSize(12);
        List<Equipment> result =
                this.beforeList(IEqEquipmentDao.class, filter).selectList(ew);
        
        PageInfo<Equipment> equipmentLists=new PageInfo<>(result);
        
        List<Equipment> list =equipmentLists.getList();
        List<EquipmentStatusVO> equipVO =new ArrayList<>();
        for(Equipment equipment : list){
        	
            equipVO.add(
                    DataTransformUtil.changeEquipmentStatusVO(equipment));
        }
        
        BasePageInfo<EquipmentStatusVO> pageInfo =new BasePageInfo<>(equipVO);
        pageInfo.setPageNum(equipmentLists.getPageNum());
        pageInfo.setPageSize(equipmentLists.getPageSize());
        pageInfo.setTotal(equipmentLists.getTotal());
        pageInfo.setPages(equipmentLists.getPages());
        
        
        return pageInfo;
    }

}
